﻿#include "FITKAbaqusHDF5AdaptorAssembly.h"
#include "FITKAbaqusHDF5AdaptorCoordinateSystem.h"
#include "FITKAbaqusHDF5AdaptorInertia.h"
#include "FITKAbaqusHDF5AdaptorDashpotPoint2Point.h"
#include "FITKAbaqusHDF5AdaptorConnectorAssignment.h"
#include "FITK_Kernel/FITKCore/FITKDataRepo.h"
#include "FITK_Kernel/FITKCore/FITKVec3D.h"
#include "FITK_Kernel/FITKCore/FITKEnumTransformer.hpp"
#include "FITK_Interface/FITKInterfaceIO/FITKAbstractHDF5Reader.h"
#include "FITK_Interface/FITKInterfaceIO/FITKAbstractHDF5Writer.h"
#include "FITK_Interface/FITKInterfaceModel/FITKNodeList.h"
#include "FITK_Interface/FITKInterfaceModel/FITKComponentManager.h"
#include "FITK_Interface/FITKInterfaceModel/FITKModelSet.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaAssembly.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaEngineeringFeature.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaTransform.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaRefPoint.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaAbstractSpringDashpot.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaSpringDashpotPoint2Point.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaSpringDashpotManager.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaEngineeringFeature.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaInertiaManager.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaInertiaPointMassInertia.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaWire.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaConnectorAssignmentManager.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaConnectorAssignment.h"


#include "H5Cpp.h"
#include <array>
namespace IO
{
    QString FITKAbaqusHDF5AdaptorAssembly::getAdaptorClass()
    {
        return "FITKAbaqusHDF5AdaptorAssembly";
    }

    bool FITKAbaqusHDF5AdaptorAssembly::adaptR()
    {
        return FITKInterfaceHDF5AdaptorAssembly::adaptR();
    }

    bool FITKAbaqusHDF5AdaptorAssembly::adaptW()
    {
        return FITKInterfaceHDF5AdaptorAssembly::adaptW();
    }

    bool FITKAbaqusHDF5AdaptorAssembly::readAssembly(Interface::FITKAssembly* assembly, H5::Group& h5Group)
    {
        auto abaAssembly = dynamic_cast<Interface::FITKAbaAssembly*>(assembly);
        if (!abaAssembly || !_reader || !abaAssembly->getComponentManager()) return false;
        bool isR = true;
        bool isValid = false;
        isR &= FITKInterfaceHDF5AdaptorAssembly::readAssembly(assembly, h5Group);

        if (h5Group.nameExists("Nodes"))
        {
            //节点
            auto h5Nodes = h5Group.openGroup("Nodes");
            auto nodes = abaAssembly->getPoints();
            if (!nodes) return false;
            isR &= readNode(nodes, h5Nodes);
        }

        //参考点
        if (h5Group.nameExists("RefPoints"))
        {
            auto h5RefPoint = h5Group.openGroup("RefPoints");
            auto refPointManager = abaAssembly->getRefPoints();
            isR &= readRefPoint(refPointManager, h5RefPoint);
        }

        //移除默认的坐标系管理器
        if (abaAssembly->getTransformManager()->getDataCount() == 1)
            abaAssembly->getTransformManager()->removeDataByIndex(0);

        if (h5Group.nameExists("CoordinateSystems"))
        {
            //坐标系
            H5::Group CoordinateSystemsGroup = h5Group.openGroup("CoordinateSystems");
            int coordinateSystemCount = CoordinateSystemsGroup.getNumAttrs();
            for (int i = 0; i < coordinateSystemCount; ++i)
            {
                QString componentIndex = QString::number(i);
                auto name = readStrAttribute(CoordinateSystemsGroup, componentIndex.toStdString());
                if (!CoordinateSystemsGroup.nameExists(name))
                {
                    _reader->consoleMessage(3, QString("Read CoordinateSystem Error, name : %1").arg(QString::fromStdString(name)));
                    continue;
                }
                auto CoordinateSystemGroup = CoordinateSystemsGroup.openGroup(name);
                isR &= readCoordinateSystem(CoordinateSystemGroup);
            }
        }

        //读取Inertia子节点
        if (h5Group.nameExists("Inertias"))
        {
            H5::Group inertiasGroup = h5Group.openGroup("Inertias");
            int inertiasCount = inertiasGroup.getNumAttrs();

            for (int i = 0; i < inertiasCount; ++i)
            {
                QString componentIndex = QString::number(i);
                auto name = readStrAttribute(inertiasGroup, componentIndex.toStdString());
                if (!inertiasGroup.nameExists(name)) return false;
                H5::Group inertiaGroup = inertiasGroup.openGroup(name);
                isR &= readInertia(inertiaGroup);
            }
        }

        //读取SpringDashs子节点
        if (h5Group.nameExists("SpringDashs"))
        {
            H5::Group springDashsGroup = h5Group.openGroup("SpringDashs");
            int springDashsCount = springDashsGroup.getNumAttrs();

            for (int i = 0; i < springDashsCount; ++i)
            {
                QString componentIndex = QString::number(i);
                auto name = readStrAttribute(springDashsGroup, componentIndex.toStdString());

                H5::Group springDashGroup = springDashsGroup.openGroup(name);
                isR &= readSpringDashpot(springDashGroup);
            }
        }

        //读取FITKAbaWire子节点
        if (h5Group.nameExists("AbaWires"))
        {
            H5::Group wiresGroup = h5Group.openGroup("AbaWires");
            int wiresCount = wiresGroup.getNumAttrs();

            for (int i = 0; i < wiresCount; ++i)
            {
                QString componentIndex = QString::number(i);
                auto name = readStrAttribute(wiresGroup, componentIndex.toStdString());

                H5::Group wireGroup = wiresGroup.openGroup(name);
                isR &= readWire(wireGroup);
            }
        }

        //读取ConnectorAssign子节点
        if (h5Group.nameExists("ConnectorAssigns"))
        {
            H5::Group connectorAssignsGroup = h5Group.openGroup("ConnectorAssigns");
            int count = connectorAssignsGroup.getNumAttrs();

            for (int i = 0; i < count; ++i)
            {
                auto name = readStrAttribute(connectorAssignsGroup, std::to_string(i));

                H5::Group connectorAssignGroup = connectorAssignsGroup.openGroup(name);
                isR &= readConnectorAssign(connectorAssignGroup);
            }
        }

        return isR;
    }

    bool FITKAbaqusHDF5AdaptorAssembly::readNode(Interface::FITKNodeList* nodes, H5::Group& h5Group)
    {
        if (nodes == nullptr) return false;

        if (!h5Group.nameExists("NodeIDs")) return false;
        auto PointIDSet = h5Group.openDataSet("NodeIDs");
        int n, m;
        if (!getDataSetDim(h5Group, "Nodes", n, m)) return false;
        auto pointsSet = h5Group.openDataSet("Nodes");

        //点
        hsize_t       dimPtData[2]{ n ,m };// 行数 // 列数
        H5::DataSpace ptDataSpace(2, dimPtData);
        //点ID
        hsize_t       dimPtIDData[2]{ n ,1 };// 行数 // 列数
        H5::DataSpace ptIDDataSpace(2, dimPtIDData);

        //点数据
        hsize_t       dim3[] = { 3 };
        H5::DataSpace mspace3(1, dim3);
        //点ID数据
        hsize_t       dim1[] = { 1 };
        H5::DataSpace mspace1(1, dim1);

        //表格
        hsize_t       coordPtData[3][2];
        coordPtData[0][1] = 0;
        coordPtData[1][1] = 1;
        coordPtData[2][1] = 2;

        for (int i = 0; i < n; ++i)
        {
            coordPtData[0][0] = i;
            coordPtData[1][0] = i;
            coordPtData[2][0] = i;

            //点
            std::array< double, 3 >  point;
            ptDataSpace.selectElements(H5S_SELECT_SET, 3, (const hsize_t*)coordPtData);
            pointsSet.read(&point, H5::PredType::NATIVE_DOUBLE, mspace3, ptDataSpace);

            //点ID
            int pID;
            ptIDDataSpace.selectElements(H5S_SELECT_SET, 1, (const hsize_t*)coordPtData);
            PointIDSet.read(&pID, H5::PredType::NATIVE_INT, mspace1, ptIDDataSpace);
            nodes->addNode(pID, point[0], point[1], point[2]);
        }
        return true;
    }

    bool FITKAbaqusHDF5AdaptorAssembly::readRefPoint(Interface::FITKAbaRefPointManager* refPointManager, H5::Group& h5Group)
    {
        auto abaAssembly = dynamic_cast<Interface::FITKAbaAssembly*>(_dataObj);

        if (!refPointManager || !abaAssembly) return false;
        bool isR = true;

        int count = h5Group.getNumAttrs();
        for (int i = 0; i < count; ++i)
        {
            QString indexName = QString::number(i);
            auto strName = readStrAttribute(h5Group, indexName.toStdString());
            if (!h5Group.nameExists(strName)) return true;
            auto refPointGroup = h5Group.openGroup(strName);
            int ComponentID = readIntAttribute(refPointGroup, "ComponentID");
            int ComponentModelID = readIntAttribute(refPointGroup, "ComponentModelID");
            auto refPoint = abaAssembly->getRefPointBySet(ComponentID, ComponentModelID);
            if (!refPoint) return false;
            isR &= readNDataObject(refPoint, refPointGroup);
        }
        return isR;
    }

    bool FITKAbaqusHDF5AdaptorAssembly::readCoordinateSystem(H5::Group& h5Group)
    {
        auto abaAssembly = dynamic_cast<Interface::FITKAbaAssembly*>(_dataObj);
        if (!abaAssembly) return false;
        bool isValid = false;
        if (!h5Group.attrExists("SysType")) return false;;
        auto sSysType = readStrAttribute(h5Group, "SysType");
        //枚举转换字符
        Core::FITKEnumTransfer<Interface::FITKCoordinateSystem::FCSysType> fitkTypeTrafer;
        auto eSysType = fitkTypeTrafer.fromString(QString::fromStdString(sSysType), isValid);
        if (!isValid) return false;

        Interface::FITKAbaTransform* transform = new Interface::FITKAbaTransform(eSysType);
        abaAssembly->getTransformManager()->appendDataObj(transform);

        //调用coordinateSystem适配器读写
        if (!transform)return false;
        auto adaptor = FITKIOADAPTORFACTORY->createT<FITKAbaqusHDF5AdaptorCoordinateSystem>("HDF5", "Interface::FITKAbaTransform");
        if (adaptor == nullptr) return false;
        adaptor->setFileReader(_reader);
        adaptor->setDataObject(transform);
        adaptor->setH5GroupData(h5Group);
        bool ok = adaptor->adaptR();
        delete adaptor;
        if (!ok)
        {
            delete transform;
            _reader->consoleMessage(3, QString("Read Assembly CoordinateSystem Error,File:%1 Line:%2").arg(__FILE__).arg(__LINE__));
        }
        return ok;
    }

    bool FITKAbaqusHDF5AdaptorAssembly::readInertia(H5::Group & h5Group)
    {
        auto abaAssembly = dynamic_cast<Interface::FITKAbaAssembly*>(_dataObj);
        if (!abaAssembly) return false;
        bool isValid = false;

        auto sInertiaType = readStrAttribute(h5Group, "InertiaType");
        //枚举转换字符
        Core::FITKEnumTransfer<Interface::FITKAbaAbstractInertia::FITKAbaInertiaType> fitkTypeTrafer;
        auto eInertiaType = fitkTypeTrafer.fromString(QString::fromStdString(sInertiaType), isValid);
        if (!isValid) return false;
        Interface::FITKAbaAbstractInertia* inertia{};
        if (eInertiaType == Interface::FITKAbaAbstractInertia::FITKAbaInertiaType::PointMassInertia)
        {
            inertia = new Interface::FITKAbaInertiaPointMassInertia();
        }
        else if (eInertiaType == Interface::FITKAbaAbstractInertia::FITKAbaInertiaType::NonstructuralMass)
        {
            return false;
        }
        else if (eInertiaType == Interface::FITKAbaAbstractInertia::FITKAbaInertiaType::HeatCapacitance)
        {
            return false;
        }
        else return false;

        auto partEngineerFeature = abaAssembly->getAssemblyEngineerFeature();
        if (!partEngineerFeature) return false;
        auto inertaManager = partEngineerFeature->getInertiaManager();
        if (!inertaManager) return false;
        inertaManager->appendDataObj(inertia);

        //调用惯量适配器读写
        auto adaptor = FITKIOADAPTORFACTORY->createT<FITKAbaqusHDF5AdaptorInertia>("HDF5", "Interface::FITKAbaAbstractInertia");
        if (adaptor == nullptr) return false;
        adaptor->setFileReader(_reader);
        adaptor->setDataObject(inertia);
        adaptor->setH5GroupData(h5Group);
        bool ok = adaptor->adaptR();
        delete adaptor;
        if (!ok)
        {
            delete inertia;
            _reader->consoleMessage(3, QString("Read Part Inertia Error, File:%1 Line:%2").arg(__FILE__).arg(__LINE__));
        }
        return ok;
    }

    bool FITKAbaqusHDF5AdaptorAssembly::readSpringDashpot(H5::Group & h5Group)
    {
        auto abaAssembly = dynamic_cast<Interface::FITKAbaAssembly*>(_dataObj);
        if (!abaAssembly) return false;
        bool isValid = false;
        auto sType = readStrAttribute(h5Group, "Type");
        //枚举转换字符
        Core::FITKEnumTransfer<Interface::FITKAbaAbstractSpringDashpot::SpringDashpotType> fitkTypeTrafer;
        auto eType = fitkTypeTrafer.fromString(QString::fromStdString(sType), isValid);
        if (!isValid) return false;
        Interface::FITKAbaAbstractSpringDashpot* springDashpot{};
        if (eType == Interface::FITKAbaAbstractSpringDashpot::SpringDashpotType::ConnectTwoPoints)
        {
            springDashpot = new Interface::FITKAbaSpringDashpotPoint2Point();
        }
        else return false;

        auto partEngineerFeature = abaAssembly->getAssemblyEngineerFeature();
        if (!partEngineerFeature) return false;
        auto springDashManager = partEngineerFeature->getSpringDashManager();
        if (!springDashManager) return false;
        springDashManager->appendDataObj(springDashpot);

        if (!springDashpot) return false;
        auto adaptor = FITKIOADAPTORFACTORY->createT<FITKAbaqusHDF5AdaptorDashpotPoint2Point>("HDF5", "Interface::FITKAbaAbstractSpringDashpot");
        if (adaptor == nullptr) return false;
        adaptor->setFileReader(_reader);
        adaptor->setDataObject(springDashpot);
        adaptor->setH5GroupData(h5Group);
        bool ok = adaptor->adaptR();
        delete adaptor;
        if (!ok)
        {
            delete springDashpot;
            _writer->consoleMessage(3, QString("Read Assembly SpringDashpot Error, File:%1 Line:%2").arg(__FILE__).arg(__LINE__));
        }
        return ok;
    }

    bool FITKAbaqusHDF5AdaptorAssembly::readWire(H5::Group & h5Group)
    {
        auto abaAssembly = dynamic_cast<Interface::FITKAbaAssembly*>(_dataObj);
        if (!abaAssembly) return false;
        bool isValid = false;

        Interface::FITKAbaWire* wite = new Interface::FITKAbaWire();
        abaAssembly->getWireManager()->appendDataObj(wite);
        auto adaptor = FITKIOADAPTORFACTORY->createT<FITKAbaqusHDF5AdaptorAbaWire>("HDF5", wite);
        if (adaptor == nullptr) return false;
        adaptor->setFileReader(_reader);
        adaptor->setDataObject(wite);
        adaptor->setH5GroupData(h5Group);
        bool ok = adaptor->adaptR();
        delete adaptor;
        if (!ok)
        {
            delete wite;
            _reader->consoleMessage(3, QString("Read Assembly Wire Error, File:%1 Line:%2").arg(__FILE__).arg(__LINE__));
        }
        return ok;
    }

    bool FITKAbaqusHDF5AdaptorAssembly::readConnectorAssign(H5::Group & h5Group)
    {
        auto abaAssembly = dynamic_cast<Interface::FITKAbaAssembly*>(_dataObj);
        if (!abaAssembly) return false;
        bool isValid = false;

        Interface::FITKAbaConnectorAssignment* ca = new Interface::FITKAbaConnectorAssignment;
        abaAssembly->getConnectorAssignManager()->appendDataObj(ca);

        auto adaptor = FITKIOADAPTORFACTORY->createT<FITKAbaqusHDF5AdaptorConnectorAssignment>("HDF5", ca);
        if (adaptor == nullptr) return false;
        adaptor->setFileReader(_reader);
        adaptor->setDataObject(ca);
        adaptor->setH5GroupData(h5Group);
        bool ok = adaptor->adaptR();
        delete adaptor;
        if (!ok)
        {
            delete ca;
            _reader->consoleMessage(3, QString("Read Assembly ConnectorAssignment Error, File:%1 Line:%2").arg(__FILE__).arg(__LINE__));
        }
        return ok;
    }


    bool FITKAbaqusHDF5AdaptorAssembly::writeAssembly(Interface::FITKAssembly* assembly, H5::Group& h5Group)
    {
        auto abaAssembly = dynamic_cast<Interface::FITKAbaAssembly*>(assembly);
        if (!abaAssembly || !_writer) return false;

        bool isW = true;
        isW &= FITKInterfaceHDF5AdaptorAssembly::writeAssembly(abaAssembly, h5Group);
        //节点
        auto h5Nodes = h5Group.createGroup("Nodes");
        auto nodes = abaAssembly->getPoints();
        isW &= writeNode(nodes, h5Nodes);
        //参考点
        auto h5RefPoint = h5Group.createGroup("RefPoints");
        auto refPointManager = abaAssembly->getRefPoints();
        isW &= writeRefPoint(refPointManager, h5RefPoint);

        //创建CoordinateSystemGroup子节点
        auto CoordinateSystemManager = abaAssembly->getTransformManager();
        H5::Group CoordinateSystemsGroup = h5Group.createGroup("CoordinateSystems");
        for (int i = 0; i < CoordinateSystemManager->getDataCount(); ++i)
        {
            auto CoordinateSystemData = CoordinateSystemManager->getDataByIndex(i);
            isW &= writeCoordinateSystem(CoordinateSystemData, CoordinateSystemsGroup);
        }

        //创建Inertia子节点
        auto inertiaManager = abaAssembly->getAssemblyEngineerFeature()->getInertiaManager();
        if (!inertiaManager) return false;
        H5::Group inertiasGroup = h5Group.createGroup("Inertias");
        for (int i = 0; i < inertiaManager->getDataCount(); ++i)
        {
            auto inertiaData = inertiaManager->getDataByIndex(i);
            isW &= writeInertia(inertiaData, inertiasGroup);
        }

        //创建SpringDash子节点
        auto springDashsManager = abaAssembly->getAssemblyEngineerFeature()->getSpringDashManager();
        if (!springDashsManager) return false;
        H5::Group springDashsGroup = h5Group.createGroup("SpringDashs");
        for (int i = 0; i < springDashsManager->getDataCount(); ++i)
        {
            auto springDashData = springDashsManager->getDataByIndex(i);
            isW &= writeSpringDashpot(springDashData, springDashsGroup);
        }

        //创建FITKAbaWire子节点
        auto wireManager = abaAssembly->getWireManager();
        if (!wireManager) return false;
        H5::Group wiresGroup = h5Group.createGroup("AbaWires");
        for (int i = 0; i < wireManager->getDataCount(); ++i)
        {
            auto wireData = wireManager->getDataByIndex(i);
            isW &= writeWire(wireData, wiresGroup);
        }

        //创建ConnectorAssign子节点
        auto caManager = abaAssembly->getConnectorAssignManager();
        if (!caManager) return false;
        H5::Group connectorAssignsGroup = h5Group.createGroup("ConnectorAssigns");
        for (int i = 0; i < caManager->getDataCount(); ++i)
        {
            auto caData = caManager->getDataByIndex(i);
            isW &= writeConnectorAssign(caData, connectorAssignsGroup);
        }

        return isW;
    }

    bool FITKAbaqusHDF5AdaptorAssembly::writeNode(Interface::FITKNodeList* nodes, H5::Group& h5Group)
    {
        if (!nodes) return false;
        int nodeCount = nodes->getNodeCount();
        //点
        hsize_t       dimPtData[2]{ nodeCount ,3 };// 行数 // 列数
        H5::DataSpace ptDataSpace(2, dimPtData);
        H5::DataSet   ptData = h5Group.createDataSet("Nodes", H5::PredType::NATIVE_DOUBLE, ptDataSpace);
        //点ID
        hsize_t       dimPtIDData[2]{ nodeCount ,1 };// 行数 // 列数
        H5::DataSpace ptIDDataSpace(2, dimPtIDData);
        H5::DataSet   ptIDData = h5Group.createDataSet("NodeIDs", H5::PredType::NATIVE_ULLONG, ptIDDataSpace);

        // 写入点数据
        hsize_t       dim1[] = { 1 };
        H5::DataSpace mspace1(1, dim1);
        //写入点ID数据
        hsize_t       dim3[] = { 3 };
        H5::DataSpace mspace3(1, dim3);

        //表格
        hsize_t       coordPtData[3][2];
        coordPtData[0][1] = 0;
        coordPtData[1][1] = 1;
        coordPtData[2][1] = 2;
        for (int i = 0; i < dimPtData[0]; ++i)
        {
            coordPtData[0][0] = i;
            coordPtData[1][0] = i;
            coordPtData[2][0] = i;
            //节点
            auto node = nodes->getNodeAt(i);
            const std::array< double, 3 > nodeData{ node->x() ,node->y() ,node->z() };
            ptDataSpace.selectElements(H5S_SELECT_SET, 3, (const hsize_t*)coordPtData);
            ptData.write(&nodeData, H5::PredType::NATIVE_DOUBLE, mspace3, ptDataSpace);
            //节点ID
            int nID = node->getNodeID();
            ptIDDataSpace.selectElements(H5S_SELECT_SET, 1, (const hsize_t*)coordPtData);
            ptIDData.write(&nID, H5::PredType::NATIVE_INT, mspace1, ptIDDataSpace);
        }
        return true;
    }

    bool FITKAbaqusHDF5AdaptorAssembly::writeRefPoint(Interface::FITKAbaRefPointManager* refPointManager, H5::Group& h5Group)
    {
        if (!refPointManager) return false;
        bool isW = true;
        int count = refPointManager->getDataCount();
        for (int i = 0; i < count; ++i)
        {
            auto refPoint = refPointManager->getDataByIndex(i);


            std::string groupName = createParentAttribute(refPoint, h5Group);
            if (groupName.empty())return false;

            int ComponentID = refPoint->getComponentID();
            int ComponentModelID = refPoint->getComponentModelID();

            _h5CreateGroup = h5Group.createGroup(groupName);

            writeIntAttribute(_h5CreateGroup, "ComponentID", &ComponentID);
            writeIntAttribute(_h5CreateGroup, "ComponentModelID", &ComponentModelID);
            isW &= writeNDataObject(refPoint, _h5CreateGroup);
        }
        return isW;
    }

    bool FITKAbaqusHDF5AdaptorAssembly::writeCoordinateSystem(Interface::FITKCoordinateSystem* coordinateSystem, H5::Group& h5Group)
    {
        //调用coordinateSystem适配器读写
        if (!coordinateSystem)return false;
        bool ok = false;
        auto adaptor = FITKIOADAPTORFACTORY->createT<FITKAbaqusHDF5AdaptorCoordinateSystem>("HDF5", "Interface::FITKAbaTransform");
        if (adaptor == nullptr) return false;
        adaptor->setFileWriter(_writer);
        adaptor->setDataObject(coordinateSystem);
        adaptor->setH5GroupData(h5Group);
        ok = adaptor->adaptW();
        delete adaptor;
        if (!ok) _writer->consoleMessage(3, QString("Write Assembly CoordinateSystem Error,File:%1 Line:%2").arg(__FILE__).arg(__LINE__));
        return ok;
    }

    bool FITKAbaqusHDF5AdaptorAssembly::writeInertia(Interface::FITKAbaAbstractInertia* inertia, H5::Group & h5Group)
    {
        //调用惯量适配器读写
        if (!inertia)return false;
        auto adaptor = FITKIOADAPTORFACTORY->createT<FITKAbaqusHDF5AdaptorInertia>("HDF5", "Interface::FITKAbaAbstractInertia");
        if (adaptor == nullptr) return false;
        adaptor->setFileWriter(_writer);
        adaptor->setDataObject(inertia);
        adaptor->setH5GroupData(h5Group);
        bool ok = adaptor->adaptW();
        delete adaptor;
        if (!ok) _writer->consoleMessage(3, QString("Write Assembly Inertia Error, File:%1 Line:%2").arg(__FILE__).arg(__LINE__));
        return ok;
    }

    bool FITKAbaqusHDF5AdaptorAssembly::writeSpringDashpot(Interface::FITKAbaAbstractSpringDashpot* springDashpot, H5::Group & h5Group)
    {
        if (!springDashpot) return false;
        auto adaptor = FITKIOADAPTORFACTORY->createT<FITKAbaqusHDF5AdaptorDashpotPoint2Point>("HDF5", "Interface::FITKAbaAbstractSpringDashpot");
        if (adaptor == nullptr) return false;
        adaptor->setFileWriter(_writer);
        adaptor->setDataObject(springDashpot);
        adaptor->setH5GroupData(h5Group);
        bool ok = adaptor->adaptW();
        delete adaptor;
        if (!ok) _writer->consoleMessage(3, QString("Write Assembly SpringDashpot Error, File:%1 Line:%2").arg(__FILE__).arg(__LINE__));
        return ok;
    }

    bool FITKAbaqusHDF5AdaptorAssembly::writeWire(Interface::FITKAbaWire* wite, H5::Group & h5Group)
    {
        if (!wite) return false;
        auto adaptor = FITKIOADAPTORFACTORY->createT<FITKAbaqusHDF5AdaptorAbaWire>("HDF5", wite);
        if (adaptor == nullptr) return false;
        adaptor->setFileWriter(_writer);
        adaptor->setDataObject(wite);
        adaptor->setH5GroupData(h5Group);
        bool ok = adaptor->adaptW();
        delete adaptor;
        if (!ok) _writer->consoleMessage(3, QString("Write Assembly Wire Error, File:%1 Line:%2").arg(__FILE__).arg(__LINE__));
        return ok;
    }

    bool FITKAbaqusHDF5AdaptorAssembly::writeConnectorAssign(Interface::FITKAbaConnectorAssignment* ca, H5::Group & h5Group)
    {
        if (!ca) return false;
        auto adaptor = FITKIOADAPTORFACTORY->createT<FITKAbaqusHDF5AdaptorConnectorAssignment>("HDF5", ca);
        if (adaptor == nullptr) return false;
        adaptor->setFileWriter(_writer);
        adaptor->setDataObject(ca);
        adaptor->setH5GroupData(h5Group);
        bool ok = adaptor->adaptW();
        delete adaptor;
        if (!ok) _writer->consoleMessage(3, QString("Write Assembly ConnectorAssignment Error, File:%1 Line:%2").arg(__FILE__).arg(__LINE__));
        return ok;
    }

}


